package com.sunmouse.toolkit.fragment.menu;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.adapter.HomePagerAdapter;
import com.sunmouse.toolkit.anim.MenuAnim;
import com.sunmouse.toolkit.fragment.BaseFragment;
import com.sunmouse.toolkit.fragment.chart.BrokenFragment;
import com.sunmouse.toolkit.fragment.chart.ColumnFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class VpMenuFragment extends BaseFragment {


    @BindView(R.id.m_vp)
    ViewPager mVp;
    Unbinder unbinder;

    private ArrayList<Fragment> fragments;
    private HomePagerAdapter mAdapter;

    public VpMenuFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_vp_menu, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void init() {
        fragments = new ArrayList<>();
        fragments.add(new BrokenFragment());
        fragments.add(new ColumnFragment());
        mAdapter = new HomePagerAdapter(getChildFragmentManager(), fragments);

        this.mVp.setAdapter(mAdapter);

        this.mVp.setPageTransformer(true, new MenuAnim());
        this.mVp.setCurrentItem(1);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
